<?
   require_once('config.php');
   
   $username	= getValue("username", "str", "POST", "", 1);
   $password	= getValue("password", "str", "POST", "", 1);
   $action		= getValue("action", "str", "POST", "");
   $user_id	   = 0;
   
   if($action == "login"){
      $Admin = new Administrator($username,$password);
   	$user_id = $Admin->check_login($username, $password);
   	if($user_id != 0){
   		$db_isadmin	= new db_query("SELECT adt_username, adt_type FROM administrator WHERE adt_id = " . $user_id);
   		$row			= mysql_fetch_array($db_isadmin->result);
 		   if(isset($row['adt_username'])){
            //Set SESSION
            $_SESSION['ad_type']       = $row['adt_type'];
       		$_SESSION["logged"]			= 1;
       		$_SESSION["user_id"]		   = $user_id;
       		$_SESSION["userlogin"]		= $username;
       		$_SESSION["password"]		= md5($password);
            redirect('index.php');
   		} 
   		
   		
   		//$_SESSION["checsum"]			= md5($user_id . "|" . $username . "|" . md5($password) . "|" . $key_checksum);
   		unset($db_isadmin);
   	}
   }
   //Check logged
   $logged = getValue("logged", "int", "SESSION", 0);
?>
<!DOCTYPE HTML>
<head>
	<meta http-equiv="content-type" content="text/html" />
	<meta name="author" content="lovemoon" charset="UTF-8"/>
   <link href="theme/css/login.css" rel="stylesheet" type="text/css"/>
   <link href="theme/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
	<title>Đăng nhập hệ thống CMS</title>
</head>

<body>

<div class="loginBox">        
  <div class="loginHead">
      <p>Đăng nhập hệ thống</p>
  </div>
  <form class="form-horizontal" action="<?=$_SERVER['REQUEST_URI']?>" method="POST">
      <div class="control-group">
          <label>Email</label>                
          <input type="text" id="inputEmail" name="username"/>
      </div>
      <div class="control-group">
          <label >Password</label>                
          <input type="password" id="inputPassword" name="password"/>                
      </div>
      <div class="form-actions" style="padding: 10px 20px;">
          <input class="btn btn-info submit" type="submit" value="Login"/>
          <input name="action" type="hidden" value="login"/>
      </div>
  </form>        
  
</div>

</body>
</html>